<?php
/* 
* [***********************]
* @author: mazhenyu[houdunwangmzy@163.com]
* @Date:   2014-06-23 16:04:01
* @Last Modified time: 2014-06-25 17:15:28
*/
class LogoControl extends CommonControl{

	public function index(){
		
		if(!empty($_GET['code'])&&!empty($_GET['state']))
      {
         //QQ回调 数据
        $qc = new QC();
        // 获得令牌AccessToken
        $acs= $qc->qq_callback();
        // 获得唯一标识用户id，用于存入数据库当做用户名
        $oid= $qc->get_openid();
        // 传递令牌与用户唯一标识，获得用户信息 
        $qc = new QC($acs,$oid); 
        $userInfo= $qc->get_user_info(); 
        $result = K('User')->get_user_info_qq(array('oid'=>$oid),null);
        if($result)
        {
    
           session("6a992d5529f459a44fee58c733255e86",$result);
           go('index');
        }else{
          $data = array(
            //QQ数据中的NICKNAME
            'nickname' => $userInfo['nickname'],
            //QQ用户的唯王一标识
            'oid'=>$oid,

            );
          $uid = K('User')->_add($data);
          session('uid',$uid);
           session('nickname',$userInfo['nickname']);
		   if(isset($_SESSION['url'])){
				$this->success('成功登陆',$_SESSION['url']);	
				}
				$this->success('成功登陆','Index/index');

        }

        // p($userInfo);die;
      }
				
//		p($_SESSION);
		if(IS_POST){
			$result = K('user')->validate_login('index');
			if($result){
				session(md5('index'),$result);
				if(isset($_SESSION['url'])){
				$this->success('成功登陆',$_SESSION['url']);	
				}
				$this->success('成功登陆','Index/index');
			}else{
				$this->error('您的密码或用户名有误,请重新输入','');
			}
			
		}
		$this->dis('login.html');
	}
	 /**
     * [qq_login QQ登陆]
     * @return [type] [description]
     */
    public function qqlogin()
    {
      require ROOT_PATH."/Lib/Connect2.1/API/qqConnectAPI.php";
       $qc = new QC(); 
       $qc->qq_login();
    }
     /**
     * [sinalogin 新浪登陆]
     * @return [type] [description]
     */
    public function sinalogin()
    {
      include_once( ROOT_PATH.'/sina/config.php' );
     include_once( ROOT_PATH.'/sina/saetv2.ex.class.php' );
      $o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
      $code_url = $o->getAuthorizeURL( WB_CALLBACK_URL );
    echo "<script>location.href='$code_url?';</script>"; 
    }
}
?>
